package org.geekbang;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.Assert;

/**
 * @author leo
 */
@SpringBootApplication
public class CustomApplication extends SpringBootServletInitializer
{
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(CustomApplication.class);
    }

    public static void main(String[] args )
    {
        //非Web 测试
        ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(CustomApplication.class)
                .web(WebApplicationType.NONE).run(args);
        Assert.isTrue(applicationContext.containsBean("customApplicationRunner"),"ApplicationRunner Bean exists");
        //Web 测试
         applicationContext = SpringApplication.run(CustomApplication.class);
        Assert.isTrue(applicationContext.containsBean("customApplicationRunner"),"ApplicationRunner Bean not exists");
        applicationContext.close();

    }
}
